﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.DAL;
using Gift.Model;
using Gift.WebApp;

namespace WebApp.admin.warehouse
{
    public partial class warehouseGoodsRealyCount : BaseAdmin
    {
        tbWarehouseGoodsInventoryDetail oWarehouseGoodsInventoryDetail;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                base.ValidateLoginRule(Gift.Model.ENUM.ERule.WarehousesInventory);
                this.BuildForm();
            }
        }

        void BuildForm()
        {
             oWarehouseGoodsInventoryDetail = BaseFactory.theWarehouseGoodsInventoryDetail.GetModel(int.Parse(Request.QueryString["id"]));
            if (oWarehouseGoodsInventoryDetail != null)
            {
                this.lblProName.Text = oWarehouseGoodsInventoryDetail.goodsName;
                this.lblGoodsBatchNo.Text = oWarehouseGoodsInventoryDetail.goodsBatchNo; 
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            oWarehouseGoodsInventoryDetail = BaseFactory.theWarehouseGoodsInventoryDetail.GetModel(int.Parse(Request.QueryString["id"]));
            oWarehouseGoodsInventoryDetail.realyCount = int.Parse(this.txtGoodsRealyCount.Value);
            oWarehouseGoodsInventoryDetail.differenceCount = oWarehouseGoodsInventoryDetail.paperCount - oWarehouseGoodsInventoryDetail.realyCount;
            if (BaseFactory.theWarehouseGoodsInventoryDetail.Update(oWarehouseGoodsInventoryDetail))
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"保存成功！\");  window.opener.document.location.reload();window.opener=null;window.open('','_self');window.close();</script>");
            }
            else
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"保存失败！\");</script>");
            }
        }
    }
}